#!/usr/bin/env python

import os, sys
import gtk

def copy_to_clipboard(text):
    clipboard = gtk.clipboard_get('CLIPBOARD')
    clipboard.set_text(text)
    clipboard.store()
"""
class Data:
    word = []
    List = []
    Seps = u'''~!@#$%^&*"'()_+|\=-><>?.,'''
    oc = None

    def save_temp(self, c):
        if ord(c) < 0xff:
            if c in Seps:
                return True
            else:
                return False
        return True

    def cache(self, c):
        print c
        if ord(c) < 0xff:
                if c in Seps:
                    List.append(word)
                    word = []
                else:
                    word.append(c)
                    continue

            word.append(c)
            List.append(word)
            word = []
        List.append(word)
        """

if __name__ == '__main__':
    argc = len(sys.argv)
    if argc > 1:
        v = unicode(sys.argv[1].decode('UTF-8'))
        word = []
        List = []
        Seps = u'''~!@#$%^&*"'()_+|\=-><>?.,'''
        pend = False

        for c in v:

            print c

            if ord(c) < 0xff and c not in Seps:
                ''' should pending in word '''
                if pend:
                    ''' in the middle of word '''
                    word.append(c)
                else:
                    ''' start of a word, flush old '''
                    List.append(word)
                    word = []
                    word.append(c)
                    pend = True
            else:
                if pend:
                    ''' prev is a word, flush it '''
                    List.append(word)
                    word = []
                    word.append(c)
                    pend = False
                else:
                    List.append(word)
                    word = []
                    word.append(c)
                    pend = False

            '''
            if ord(c) < 0xff:
                if c in Seps:
                    if pend:
                        List.append(word)
                        pend = False
                    else:
                        pend = False
                        word.append(c)
                        List.append(word)
                        word = []
                else:
                    word.append(c)
                    pend = True
                    continue
            else:
                word.append(c)
                List.append(word)
                word = []

                '''
        List.append(word)


        v = List[::-1]
        out = ''
        for c in v:
            out += ''.join(c)

        copy_to_clipboard(out)
        print out

